home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / funexec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.6 KB  |  116 lines

  1. /*
  2. \funcref{fun\_exec}{void fun\_exec ()}
  3.     {}
  4.     {}
  5.     {xstrdup(), getexecarg(), execmd(), xrealloc()}
  6.     {fun\_print()}
  7.     {funexec.c}
  8.     {
  9.  
  10.         This function is called when an {\em op\_exec} opcode is encountered
  11.         in the binary makefile. At this point, the stack is expected to hold
  12.         the following information:
  13.  
  14.         \begin{itemize}
  15.  
  16.             \item The last pushed value ({\em stack[sp]} holds the number of
  17.             arguments to the original {\em exec()} statement.
  18.  
  19.             \item The value pushed before that ({\em stack [sp-1]}) holds the
  20.             execution mode: 0 = checked, !0 = not checked. When the execution
  21.             mode is checked, any exit status which is non-zero leads to an
  22.             error.
  23.  
  24.             \item The value pushed before that ({\em stack [sp-2]}) holds the
  25.             command to execute; a string.
  26.  
  27.             \item Other pushed values are the remaining arguments.
  28.  
  29.         \end{itemize}
  30.  
  31.         {\em fun\_exec()} initializes an array of command strings and
  32.         retrieves arguments. When the length of the command list is about to
  33.         exceed {\em MAXCMDLEN} (see {\em icm.h}), the command is flushed by
  34.         calling {\em execmd()}.
  35.  
  36.     }
  37. */
  38.  
  39. #include "icm-exec.h"
  40.  
  41. static char **initcmd (cmd)
  42. char **cmd;
  43. {
  44.     register int
  45.         i;
  46.  
  47.     if (cmd)
  48.         for (i = 0; cmd [i]; i++)
  49.             xrealloc (cmd [i], 0);
  50.     xrealloc (cmd, 0);
  51.     
  52.     cmd = xrealloc (NULL, 3 * sizeof (char *));
  53.     cmd [0] = xstrdup (stack [sp - 2].vu.i->ls.str);
  54.     
  55.     if (strlen (cmdhead))
  56.     {
  57.         cmd [1] = xstrdup (cmdhead);
  58.         cmd [2] = NULL;
  59.     }
  60.     else
  61.         cmd [1] = NULL;
  62.  
  63.     return (cmd);
  64. }
  65.  
  66. void fun_exec ()
  67. {
  68.     register int
  69.         i,
  70.         nargs,
  71.         mode,
  72.         nextarglen,
  73.         cmdlen,
  74.         getnewarg;
  75.     int
  76.         newelement;
  77.     register char
  78.         *nextarg = NULL,
  79.         **cmd;
  80.  
  81.     nargs = stack [sp].vu.intval;
  82.     mode  = stack [sp - 1].vu.intval;
  83.  
  84.     cmd = initcmd (NULL);
  85.  
  86.     i = 3;
  87.     getnewarg = 1;
  88.     while (i <= nargs)
  89.     {
  90.         if (getnewarg)
  91.             nextarg = getexecarg (i, &newelement);
  92.         else
  93.             getnewarg = 1;
  94.         nextarglen = strlen (nextarg);
  95.         cmdlen = getcmdlen (cmd);
  96.         if (cmdlen + nextarglen + strlen (cmdtail) >= MAXCMDLEN)
  97.         {
  98.             cmd = execmd (cmd, mode);
  99.             cmd = initcmd (cmd);
  100.             getnewarg = 0;
  101.         }
  102.         else
  103.         {
  104.             cmd = addcmd (cmd, nextarg);
  105.             i += newelement;
  106.             xrealloc (nextarg, 0);
  107.         }
  108.     }
  109.  
  110.     cmd = execmd (cmd, mode);
  111.  
  112.     for (i = 0; cmd [i]; i++)
  113.         xrealloc (cmd [i], 0);
  114.     xrealloc (cmd, 0);
  115. }
  116.